// import './index.scss';

import XHeader from 'vux/src/components/x-header/index.vue'
import Tab from 'vux/src/components/tab/tab.vue'
import TabItem from 'vux/src/components/tab/tab-item.vue'
import Swiper from 'vux/src/components/swiper/swiper.vue'
import SwiperItem from 'vux/src/components/swiper/swiper-item.vue'
import XButton from 'vux/src/components/x-button/index.vue'
import Flexbox from 'vux/src/components/flexbox/flexbox.vue'
import FlexboxItem from 'vux/src/components/flexbox/flexbox-item.vue'
import XProgress from 'vux/src/components/x-progress/index.vue'
import Popup from 'vux/src/components/popup/index.vue'
import Group from 'vux/src/components/group/index.vue'
import Cell from 'vux/src/components/cell/index.vue'
import Checker from 'vux/src/components/checker/checker.vue'
import CheckerItem from 'vux/src/components/checker/checker-item.vue'
import XInput from 'vux/src/components/x-input/index.vue'
import XTextarea from 'vux/src/components/x-textarea/index.vue'
import Checklist from 'vux/src/components/checklist/index.vue'

import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
// import Http from "../../common/http";

export default {
  name: 'Project',
  components: {
    XHeader, Tab, TabItem, Swiper, SwiperItem,
    XButton, Flexbox, FlexboxItem, XProgress, Popup,
    Group, Cell, Checker, CheckerItem, XInput,
    XTextarea, Checklist
  },
  data () {
    return {
      index: 0,
      // 信息反馈是否有红点  为''的时候没有  为' '的时候有
      isXinxi: ' ',
      percent1: 60,
      show: false,
      demo: 10,
      isM: '募捐中',
      userId: '',
      eventType: '',

      name: '',
      mobile: '',
      IDNum: '',
      liuyan: '',
      ifShowtt: false,

      item: 'item',
      textMoney: '',
      checkOK: true,
      isA: true,
      threshold: 50,
      minmovingdistance: 30,
      // 项目id
      event_id: '',
      // 显示哪一个模块
      witchShow: 'xiangqing',
      pageNoOther: 1,
      pageNoJuankuan: 1,
      pageSize: 5,
      eventAll: {},
      eventOther: [],
      eventJuankuan: [],
      lookMore: '查看更多',
      lookMoreJuankuans: '查看更多',
      ifselected: false,
      isID: function (value) {
        let r = /^(\d{18}|\d{17}x)$/;
        if (r.test(value)) {
          return {
            valid: true,
            msg: '身份证正确'
          }
        } else {
          return {
            valid: false,
            msg: '身份证错误'
          }
        }
      }
    }
  },
  mounted () {
    this.userId = window.sessionStorage.getItem('userId')
    this.event_id = window.sessionStorage.getItem('event_id')
    console.log(this.event_id)
    http.post(CONSTANT.EVENT_VIEW, {
      event_id: this.event_id,
      userId: this.userId
      // pageNo: this.pageNo,
      // pageSize: this.pageSize
    }, (res) => {
      console.log(res)
      if (res.code == 200) {
        this.eventAll = res.obj
        if (res.obj.feedBack == '') {
          this.isXinxi = ''
        }
        if (res.obj.eventStatus == 1) {
          this.isM = '募捐中'
        } else if (res.obj.eventStatus == 4) {
          this.isM = '已结束'
        }
        if (res.obj.eventType == 'pool') {
          this.eventType = '助困'
        } else if (res.obj.eventType == 'other') {
          this.eventType = '其它'
        } else if (res.obj.eventType == 'study') {
          this.eventType = '学习'
        } else if (res.obj.eventType == 'medicine') {
          this.eventType = '助医'
        }
        this.name = res.obj.name
        this.mobile = res.obj.telephone
        this.IDNum = res.obj.idCard
        if (res.obj.name == '' || res.obj.telephone == '' || res.obj.idCard == '') {
          this.ifShowtt = true
        }
      }
    })
    this.OtherProjects();
    this.OtherJuankuans();
  },
  methods: {
    keyups () {
      this.demo = this.textMoney
      this.ifselected = true
    },
    blurs () {
      this.ifselected = false
    },
    moreOtherProjects () {
      // 查看更多该单位项目
      this.pageNoOther++;
      this.OtherProjects()
    },
    OtherProjects () {
      // 单位发起的项目
      http.post(CONSTANT.EVENT_ORGANIZE, {
        event_id: this.event_id,
        pageNo:this.pageNoOther,
        pageSize:this.pageSize
      }, (res) => {
           console.log('发起项目')
           console.log(res)
        if (res.code == 200) {
          if (res.errmsg == '没有更多的项目') {
            this.pageNoOther--
            this.lookMore = '没有更多的项目了'
            return
          } else if (res.errmsg == '') {
            if (this.pageNoOther == 1) {
              this.eventOther = res.list
            } else {
              this.eventOther = this.eventOther.concat( res.list)
            }
          }
        }
      })
    },
    moreOtherJuankuans () {
      // 查看更多捐款
      this.pageNoJuankuan++;
      this.OtherJuankuans()
    },
    OtherJuankuans () {
      // 捐款记录
      http.post(CONSTANT.EVENT_DONATE, {
        event_id: this.event_id,
        pageNo:this.pageNoJuankuan,
        pageSize:this.pageSize
      }, (res) => {
        if (res.errmsg == '没有更多的项目') {
          this.pageNoJuankuan--
          this.lookMoreJuankuans = '没有更多的捐款记录了'
          return
        } else if (res.errmsg == '') {
          if (this.pageNoJuankuan == 1) {
            this.eventJuankuan = res.list
          } else {
            this.eventJuankuan = this.eventJuankuan.concat(res.list)
          }
        }
      })
    },
    isShow () {
      // 弹出框关闭按钮
      this.show = false
    },
    wantJuank () {
      // 我要捐款
      this.show = true
    },
    checkerWitch (value) {
      // 选择捐款金额
      console.log(this.demo)
    },
    checkOk () {
      // 是否同意用户协议
      console.log(this.checkOK)
    },
    textMoneyChange () {
    },
    goreport () {
      this.$router.push({path: '/report'})
    },
    godonation () {
      this.$router.push({path: '/donation'})
    },
    primary () {
      let num = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
      let _this = this
      if (_this.demo == '') {
        alert('请选择捐款金额!')
      } else if (!num.test(_this.demo)) {
        alert('请输入正确的金额数!（提示：只能是数字或者精确到两位小数）')
      } else if (_this.demo == 0 || _this.demo == '0.00') {
        alert('请输入正确的金额数!（提示：只能是数字或者精确到两位小数）')
      } else if (this.checkOK == false) {
        alert('请同意并接受\n《亲青筹用户协议》！')
      } else {
        http.post(CONSTANT.USER_MESSAGE, {userId: this.userId, name: this.name, idCard: this.IDNum, telephone: this.mobile, event_id: this.event_id, content: this.liuyan}, (res) => {
          console.log(res)
        })
        // window.location.href = 'http://qyc.hztangong.com/a/wxinterface/payment?' + 'witchOne=geren&userId=' +
        //   this.userId + '&money=' + this.demo + '&eventId=' + this.event_id
        this.$router.push({path: '/payment', query: {witchOne: 'geren', money: this.demo}})
      }
    }
  }
}
// else if (_this.name == '') {
//   alert('请输入您的姓名！')
// } else if (_this.mobile == '') {
//   alert('请输入您的手机号！')
// } else if (_this.$refs.mobile.valid === false) {
//   alert('请输入正确的手机号')
// } else if (_this.IDNum == '') {
//   alert('请输入您的身份证号码！')
// } else if (_this.$refs.IDNum.valid === false) {
//   alert('请输入正确的身份证号码！')
// }
